import request from "@/utils/request";
import type {
  GetAttrListParams,
  SaveOrUpdateAttrParams,
  GetAttrListResponse,
} from "./model/attrModel";

// 枚举
// 统一定义所有接口的请求地址
enum Api {
  getAttrListUrl = "/admin/product/attrInfoList",
  saveAttrUrl = "/admin/product/saveAttrInfo",
  delAttrUrl = "/admin/product/deleteAttr",
}

/**
 * 获取属性列表
 * @param GetAttrListParams 三个分类id
 * @returns GetAttrListResponse
 */
export const getAttrListApi = ({
  category1Id,
  category2Id,
  category3Id,
}: GetAttrListParams) => {
  return request.get<any, GetAttrListResponse>(
    Api.getAttrListUrl + `/${category1Id}/${category2Id}/${category3Id}`
  );
};

/**
 * 添加属性
 * @param data SaveAttrParams
 * @returns null
 */
export const saveAttrApi = (data: SaveOrUpdateAttrParams) => {
  return request.post<any, null>(Api.saveAttrUrl, data);
};

/**
 * 删除属性
 * @param id 属性id
 * @returns null
 */
export const delAttrApi = (id: number) => {
  return request.delete<any, null>(Api.delAttrUrl + `/${id}`);
};
